<?php
$this->breadcrumbs=array(
	'综合控制台'=>array($this->pre_module_url.'/index/index'),
	'广告管理'=>array($this->pre_module_url.'/adse/admin'),	
	'添加广告'
);
?>

<?php 
			$form = $this->beginWidget('CActiveForm', 
			array(
			'id'=>'zdse-form',
			//'enableAjaxValidation'=>true,
			'enableClientValidation'=>true,	
			'action'=>$this->pre_module_url.'/adse/create',
			)); ?>
                <ul class="form_list form_list2 mt10">
                	<li class="c_f"><span class="tit">选择页面：</span>
                        <div class="cont f_l">
							<?php 
                                echo CHtml::dropDownList('Adse[zna_id]',$menu1['zna_id'],Nav::model()->getTopData(),array('class'=>'mr10 s_ipt level_1 w_170','onchange'=>'afterSelect(1,this.value)','id'=>'menuselect1')); 
                                if($menu2){
                                    echo CHtml::dropDownList('Adse[zna_id2]',$menu2['zna_id'],Nav::model()->getChildData($menu1['zna_id']),array('class'=>'mr10 s_ipt level_1 w_170','onchange'=>'afterSelect(2,this.value)','id'=>'menuselect2')); 
                                    if($menu3){
                                        echo CHtml::dropDownList('Adse[zna_id3]',$menu3['zna_id'],Nav::model()->getChildData($menu2['zna_id']),array('class'=>'mr10 s_ipt level_1 w_170','onchange'=>'afterSelect(3,this.value)','id'=>'menuselect3')); 
                                    }
                                }
                            ?>
                        </div>
                    </li>
                	<li class="c_f"><span class="tit">选择广告位：</span>
                        <div class="cont f_l" id="adzonebox">
                       		<?php echo CHtml::dropDownList('Adse[zdz_id]',Yii::app()->request->getParam('zdzid',0),Adzone::model()->getAdzonesForSelect($adzone->zna_id),array('class'=>'s_ipt w_170','id'=>"adzoneselect")); ?>
                        </div>
                    </li>
                    <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_title'); ?>：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_title',array('class'=>'t_ipt w_300','maxlength'=>10)); ?></div>
                        <span id="zdstitle"><?php echo $form->error($model,'zds_title',array('class'=>'onCorrect d_i c_red2')); ?></span>
                    </li>
                    <li class="c_f">
                    	<span class="tit"><?php echo $form->label($model,'zds_desc'); ?>：</span>
						<div class="cont f_l"><?php echo $form->textarea($model,'zds_desc',array('class'=>'t_area','style'=>'height:65px;width:500px;')); ?></div>
                    	<span id="zdsdesc"><?php echo $form->error($model,'zds_desc',array('class'=>'onCorrect d_i c_red2')); ?></span>
                    </li>
                    <?php
                    	if($adzone->zdz_type==1){
					?>
                            <li class="c_f"><span class="tit">广告图片：</span>                                
                                <div class="cont f_l">
                                    <div class="adv_img f_l"><?php echo $form->textField($model,'zds_file_url',array('class'=>'t_ipt w_300','id'=>'pic1')); ?></div>
                                    <div class="adv_disc"><button id="upbutton1" type="button" onclick="file1.click();" class="mem_btn mem_btn10">上传...</button></div>
                                    <div class="adv_img f_l">
                                    	<input id="file1" class="d_n" type="file" onclick="uploadimg(1)" value="" name="image" />
                                    	<img width="<?php echo $adzone->zdz_width;?>" height="<?php echo $adzone->zdz_height;?>" id="img11" src="/images/cert_img.jpg" alt="" />
                                        <p class="c_999">最佳图片大小 <strong class="c_green3 ff_s"><?php echo $adzone->zdz_width.'*'.$adzone->zdz_height; ?></strong> </p>
                                    </div>
                                </div>
                            </li>
                    <?php							
						}else{
					?>
                            <li class="c_f"><span class="tit">swf文件：</span>
                                <div class="cont f_l">
                                    <div class="adv_img f_l"><?php echo $form->textField($model,'zds_file_url',array('class'=>'t_ipt w_300','id'=>'swf1')); ?></div>
                                    <div class="adv_disc"><button class="mem_btn mem_btn13" onclick="file2.click();" id="file2button" type="button" name="" value="" >上传...</button></div>
                                    <div class="adv_disc f_l">
                                    	<input id="file2" class="d_n" type="file" onclick="uploadswf('file2')" value="" name="imgFile" />
                                        <p class="c_999">显示大小： <strong class="c_green3 ff_s"><?php echo $adzone->zdz_width.'*'.$adzone->zdz_height; ?>px</strong> </p>
                                    </div>
                                </div>
                            </li>
                    <?php					
						}					
					?>
                    <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_img_alt'); ?>：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_img_alt',array('class'=>'t_ipt w_170','maxlength'=>100)); ?></div>
                    </li>
                    <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_url'); ?>：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_url',array('class'=>'t_ipt w_170','maxlength'=>200)); ?></div>
                    </li>
                    <?php
                    	if($adzone->zdz_associate){
					?>
                        <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_category'); ?>：</span>
                            <div class="cont f_l">
                                <?php 
                                    foreach($category as $key=>$value){
                                        echo '<input type="checkbox" name="Adse[categorys][]" value="'.$value[$catkey['id']].'"><b>'.$value[$catkey['title']].'</b></br>';
                                        if(isset($value['subcat'])){
                                            foreach($value['subcat'] as $subkey=>$subvalue){
                                            echo '<input type="checkbox" name="Adse[categorys][]" value="'.$subvalue[$catkey['id']].'">'.$subvalue[$catkey['title']];
                                        }
                                        }
                                        echo '</br>';
                                        if(isset($value['subcat']) && count($value['subcat'])){
                                            echo '</br>';
                                        }
                                    }
                                ?>
                             </div>
                        </li>
                    <?php					
						}					
					?>
                    <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_name'); ?>：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_name',array('class'=>'t_ipt w_170','maxlength'=>10)); ?></div>
                    </li>
                    <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_mob'); ?>：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_mob',array('class'=>'t_ipt w_170','maxlength'=>11)); ?></div>
                    </li>
                    <li class="c_f"><span class="tit">广告价格：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_price',array('class'=>'t_ipt w_100','value'=>'','maxlength'=>5)); ?>元</div>
                    </li>
                    <li class="c_f"><span class="tit">开始时间：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_start_time',array('class'=>'t_ipt w_100','maxlength'=>50,'onclick'=>"WdatePicker()")); ?></div>
                    </li>
                    <li class="c_f"><span class="tit">结束时间：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_end_time',array('class'=>'t_ipt w_100','maxlength'=>50,'onclick'=>"WdatePicker()")); ?></div>
                    </li>
                    <li class="c_f"><span class="tit">&nbsp;</span>
                        <div class="cont f_l"><input class="mem_btn mem_btn20 mr5" type="submit" name="" value="发布广告" /><input class="mem_btn mem_btn07" type="button" name="" value="取 消" /></div>
                    </li>
                </ul>	
            <?php $this->endWidget(); ?>
<script language="javascript" type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/My97DatePicker/WdatePicker.js"></script> 
<script src='<?php echo Yii::app()->baseUrl;?>/js/jquery.ui.widget.js'></script> 
<script src='<?php echo Yii::app()->baseUrl;?>/js/jquery.iframe-transport.js'></script> 
<script src='<?php echo Yii::app()->baseUrl;?>/js/jquery.fileupload.js'></script> 
<script>
	function afterSelect(level,menuid){
		$('#menuselect'+level).nextAll().remove();
		menuid = parseInt(menuid)==0 ? -1 : menuid;
		if(level<3){
			$.getJSON("/manage/nav/getchildmenu", { menuid: menuid, level: level }, function(data){
				if(data.amount){
					var nextLevel=parseInt(data.level)+1;
					var next = '<select class="level_'+(nextLevel)+' mr10 s_ipt w_170" onchange="afterSelect('+(nextLevel)+',this.value)" id="menuselect'+(nextLevel)+'" name="Adzone[zna_id'+(nextLevel)+']">';
					$.each(data.items, function(i,item){
						next += '<option value="'+i+'">'+item+'</option>';
					});
					next += '</select>';
					$('#menuselect'+data.level).after(next);
				}
				$.getJSON("/manage/adzone/getadzonelist", { menuid: data.menuid, level: data.level }, function(list){
					var text = '<select class="mr10 s_ipt w_170" name="Adse[zdz_id]" id="adzoneselect">';
					//text += '<option value="0">请选择</option>';
					$.each(list.items, function(i,item){
						text += '<option value="'+i+'">'+item+'</option>';
					});
					text += '</select>';
					$('#adzonebox').html(text);
				});
			});
		}
	}
	 
   function uploadimg (id) {
		   $('#file'+id).fileupload({         	
				dataType: 'json',
				url: '/Attachment/GetAjax',        
				success: function (json) {
					   if(json.upfile.errors=='1'){
							alert(json.upfile.msg);
					   }else if(json.upfile.errors=='2'){
							alert(json.upfile.msg);
					   }else{
							 //修改按钮图标
							 $('#img'+id+id).attr('src',json.upfile.file);
							 //修改按钮文本
							 $('#upbutton'+id).text('修改...');
							 //修改隐藏域值
							 $('#pic'+id).attr('value',json.upfile.file);
					   } 	
				}
			});
	};	
   function uploadswf (id) {
		   $('#'+id).fileupload({         	
				dataType: 'json',
				url: '/Attachment/GetAjax',        
				success: function (json) {
					   if(json.upfile.errors=='1'){
							alert(json.upfile.msg);
					   }else if(json.upfile.errors=='2'){
							alert(json.upfile.msg);
					   }else{
							 //修改按钮文本
							 $('#'+id+'button').text('修改...');
							 //修改隐藏域值
							 $('#swf1').attr('value',json.upfile.file);
					   } 	
				}
			});
	};		
 </script>